package com.yike.user.controller;

import com.yike.user.param.BandMachineParam;
import com.yike.user.param.InitMachineParam;
import com.yike.user.service.MachineService;
import com.yike.common.vo.MachineVo;
import lombok.extern.slf4j.Slf4j;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 设备表 控制器
 *
 * @author yike
 * @since 2024-07-19
 */
@Slf4j
@RestController
@RequestMapping("/machine")
@Api(value = "设备API", tags = {"设备管理"})
public class MachineController extends BaseController {

    @Autowired
    private MachineService machineService;

    /**
     * 添加设备表
     */
    @PostMapping("/init")
    @OperationLog(name = "设备初始校验", type = OperationLogType.ADD)
    @ApiOperation(value = "设备初始校验", response = MachineVo.class)
    public ApiResult<MachineVo> addMachine(@Validated(Add.class) @RequestBody InitMachineParam machine) throws Exception {
        MachineVo machineVo = machineService.init(machine);
        return ApiResult.ok(machineVo);
    }

    /**
     * 添加设备表
     */
    @PostMapping("/band")
    @OperationLog(name = "设备绑定", type = OperationLogType.ADD)
    @ApiOperation(value = "设备绑定", response = ApiResult.class)
    public ApiResult<Boolean> bindMachine(@Validated(Add.class) @RequestBody BandMachineParam band) throws Exception {
        machineService.band(band);
        return ApiResult.ok(true);
    }

}

